
import { _decorator, Component, Node, Vec3, Camera, find } from 'cc';
const { ccclass, property } = _decorator;
 
@ccclass('CameraControl')
export class CameraControl extends Component {
   private playerNode:Node;
    private camera:Camera;

    start () {
        this.camera = this.getComponent(Camera);
    }

    lateUpdate(){
        //x  111  400
        //y  -2776 -104
        if(!this.playerNode||!this.playerNode.name){
            if(!(this.playerNode = find("GameScene/Player"))) return;
        }
        let vec = new Vec3(this.playerNode.position.x,this.playerNode.position.y,1000)
        if(vec.y>-104) vec.y = -104;
        if(vec.y<-2776) vec.y = -2776;
        if(vec.x>400) vec.x = 400;
        if(vec.x<111) vec.x = 111;
        this.node.position = vec;
    }

    // update (deltaTime: number) {
    //     // [4]
    // }
}

/**
 * [1] Class member could be defined like this.
 * [2] Use `property` decorator if your want the member to be serializable.
 * [3] Your initialization goes here.
 * [4] Your update function goes here.
 *
 * Learn more about scripting: https://docs.cocos.com/creator/3.4/manual/zh/scripting/
 * Learn more about CCClass: https://docs.cocos.com/creator/3.4/manual/zh/scripting/ccclass.html
 * Learn more about life-cycle callbacks: https://docs.cocos.com/creator/3.4/manual/zh/scripting/life-cycle-callbacks.html
 */
